using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace ibba.src.noriskbo
{
    
    public partial class PainelListaContratos : UserControl
    {
        public delegate void EventSelectionChanged<T>(T contrato);
        public event EventSelectionChanged<ServiceOperacao.Contrato> ContratoSelecionado;

        private ViewModels.PageLancamentoManualViewModel _viewModel;
        
        //private BitmapImage imgChecked;
        //private BitmapImage imgUnchecked;
       
        public PainelListaContratos()
        {
            InitializeComponent();

            if (!App.IsDesignTime)
            {
                this.Loaded += new RoutedEventHandler(PainelListaContratos_Loaded);

                //imgChecked = new BitmapImage(new Uri(Constantes.SourceImageApp.CHECKED_MINI, UriKind.Relative));
                //imgUnchecked = new BitmapImage(new Uri(Constantes.SourceImageApp.UNCHECKED_MINI, UriKind.Relative));
            }
        }

        void PainelListaContratos_Loaded(object sender, RoutedEventArgs e)
        {
            if (this.DataContext != null) //Para evitar erro em designtime
                _viewModel = (ViewModels.PageLancamentoManualViewModel)this.DataContext;
        }

                
        #region "Check Filtro Status Contrato"

        private void chkFlagAT_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            _viewModel.FiltrarStatusAutomatico = !_viewModel.FiltrarStatusAutomatico;
            //chkFlagAT.Source = (_viewModel.FiltrarStatusAutomatico ? imgChecked : imgUnchecked);            
        }
        private void chkFlagRA_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            _viewModel.FiltrarStatusRA = !_viewModel.FiltrarStatusRA;
            //chkFlagRA.Source = (_viewModel.FiltrarStatusRA ? imgChecked : imgUnchecked);
        }
        private void chkFlagEA_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            _viewModel.FiltrarStatusEA = !_viewModel.FiltrarStatusEA;
            //chkFlagEA.Source = (_viewModel.FiltrarStatusEA ? imgChecked : imgUnchecked);
        }        
        private void chkFlagEE_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            _viewModel.FiltrarStatusEE = !_viewModel.FiltrarStatusEE;
            //chkFlagEE.Source = (_viewModel.FiltrarStatusEE ? imgChecked : imgUnchecked);
        }
        private void chkFlagAP_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            _viewModel.FiltrarStatusAP = !_viewModel.FiltrarStatusAP;
            //chkFlagAP.Source = (_viewModel.FiltrarStatusAP ? imgChecked : imgUnchecked);
        }
        private void chkFlagBO_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            _viewModel.FiltrarStatusBO = !_viewModel.FiltrarStatusBO;
        }
        private void chkFlagEB_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            _viewModel.FiltrarStatusEB = !_viewModel.FiltrarStatusEB;
        }
                
        #endregion


        private void btnExibirFiltro_Click(object sender, RoutedEventArgs e)
        {
            GridContratos.Visibility = Visibility.Visible;
        }
        private void btnMinimizarFiltro_Click(object sender, RoutedEventArgs e)
        {
            GridContratos.Visibility = Visibility.Collapsed;
        }

        private void lstContrato_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (ContratoSelecionado != null)
                ContratoSelecionado((ServiceOperacao.Contrato)lstContrato.SelectedValue);
        }

        private void btnLimparFiltro_Click(object sender, RoutedEventArgs e)
        {
            _viewModel.FiltrarContrato = string.Empty;
        }
        
    }
}
